package com.woniuxy.store.service.consumer;

import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.store.infra.model.StoreWallet;
import com.woniuxy.store.service.StoreWalletService;
import com.woniuxy.store.service.param.AddBalanceParam;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(consumerGroup = "store_balance",topic = "update_store_money")
public class StoreBalanceConsumer implements RocketMQListener<AddBalanceParam> {

    @Resource
    private StoreWalletService storeWalletService;

    @Override
    @Log("开始增加商家账户余额")
    public void onMessage(AddBalanceParam addBalanceParam) {
        StoreWallet wallet = storeWalletService.getWallet(addBalanceParam.getStoreId());
        storeWalletService.addBalance(addBalanceParam.getStoreId(),wallet.getStoreWalletId(),addBalanceParam.getAmountPaid());
    }
}
